package cn.xfdzx.android.apps.shop.adapter;

import android.view.View;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.luck.picture.lib.tools.ToastUtils;

import java.util.ArrayList;
import java.util.List;

import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.AfterMarketSelGoodsBean;
import cn.xfdzx.android.apps.shop.bean.OrderDetailInfoBeen;
import cn.xfdzx.android.apps.shop.bean.OrderListBeen;
import cn.xfdzx.android.apps.shop.util.ImageGlideUtil;
import cn.xfdzx.android.apps.shop.widget.CornerImageView;

/**
 * Creator: zf.
 * Date: 2020/9/28.
 * Description:批发申请退款商品列表选择页面适配器.
 */
public class AfterServiceMarketGoodsRequestAdapter extends BaseQuickAdapter<AfterMarketSelGoodsBean, BaseViewHolder>  {
    public OnItemOnClickListener onItemOnClickListener;
    private List<OrderListBeen.DataBean.CartInfoBean> cartInfo;//列表
    private List<AfterMarketSelGoodsBean> selGoodsBeans;
    public AfterServiceMarketGoodsRequestAdapter(@Nullable List<AfterMarketSelGoodsBean> data) {
        super(R.layout.item_aftermarketgoods_request, data);
        this.selGoodsBeans = data;
    }

    @Override
    public void setData(int index, @NonNull AfterMarketSelGoodsBean data) {
        super.setData(index, data);
    }


    @Override
    protected void convert(final BaseViewHolder viewHolder, final AfterMarketSelGoodsBean date) {
        CornerImageView iv_goods = viewHolder.getView(R.id.iv_goods);
        iv_goods.setType(CornerImageView.TYPE_ROUND);
        TextView tv_goods_add = viewHolder.getView(R.id.tv_goods_add);
        TextView tv_goods_minus = viewHolder.getView(R.id.tv_goods_minus);
        TextView tv_goods_num = viewHolder.getView(R.id.tv_goods_num);

        ImageGlideUtil.loadImage(mContext,iv_goods,date.getGoods_img());
        viewHolder.setText(R.id.tv_goods_name,date.getGoods_name())
        .setText(R.id.tv_goodssize,"包装规格: "+date.getGoods_unit())
        .setText(R.id.tv_goodsnum,"x"+date.getBuyNum());

        tv_goods_add.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                tv_goods_minus.setVisibility(View.VISIBLE);
                if (selGoodsBeans.get(viewHolder.getLayoutPosition()).getBuyNum()>selGoodsBeans.get(viewHolder.getLayoutPosition()).getNum()){
                    selGoodsBeans.get(viewHolder.getLayoutPosition()).setNum(selGoodsBeans.get(viewHolder.getLayoutPosition()).getNum()+1);
                    tv_goods_num.setText(selGoodsBeans.get(viewHolder.getLayoutPosition()).getNum()+"");
                    onItemOnClickListener.onItemAddMoveClick(viewHolder.getLayoutPosition(),selGoodsBeans);
                }else {
                    ToastUtils.s(mContext,"超过最大数量");
                    return;
                }
            }
        });

        tv_goods_minus.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (selGoodsBeans.get(viewHolder.getLayoutPosition()).getNum()==1){
                    ToastUtils.s(mContext,"最小数量是1");
                    return;
                }

                selGoodsBeans.get(viewHolder.getLayoutPosition()).setNum(selGoodsBeans.get(viewHolder.getLayoutPosition()).getNum()-1);
                tv_goods_num.setText(selGoodsBeans.get(viewHolder.getLayoutPosition()).getNum()+"");
                onItemOnClickListener.onItemAddMoveClick(viewHolder.getLayoutPosition(),selGoodsBeans);
            }
        });

    }
    public void clearDatas(){
        mData.clear();
        notifyDataSetChanged();
    }
    public void refreshDatas(List<AfterMarketSelGoodsBean> list){
        super.replaceData(list);
    }

    public void setItemAddMoveListener(OnItemOnClickListener listener){
        this.onItemOnClickListener = listener;
    }

    public interface OnItemOnClickListener {
        void onItemAddMoveClick(int position, List<AfterMarketSelGoodsBean> selGoodsBeans);
    }

}
